package com.example.smart.adapter.home

import android.app.Activity
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.example.lib.extend.setOnDoubleClickListener
import com.example.smart.R
import com.example.smart.base.adapter.BaseRecyclerAdapter
import com.example.smart.base.adapter.BaseViewHolder
import com.example.smart.databinding.ItemBanner1Binding
import com.example.smart.databinding.ItemBanner2Binding
import com.example.smart.utils.DisplayUtils

class BannerAdapter(val activity: Activity) : BaseRecyclerAdapter<ViewBinding, Int>(activity, mutableListOf(0, 1)) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<ViewBinding> {
        return if (viewType == 0) {
            BaseViewHolder(ItemBanner1Binding.bind(LayoutInflater.from(context)
                .inflate(R.layout.item_banner1, parent, false)))
        } else {
            BaseViewHolder(ItemBanner2Binding.bind(LayoutInflater.from(context)
                .inflate(R.layout.item_banner2, parent, false)))
        }

    }

    override fun onBindView(itemView: ViewBinding, bean: Int, position: Int) {
        if (getItemViewType(position) == 0) {
            with(itemView as ItemBanner1Binding) {
                itemView.ItemText.setOnDoubleClickListener {
                    DisplayUtils.toAddAnimal(activity)
                }
            }
        } else {
            with(itemView as ItemBanner2Binding) {
                itemView.ItemLinearlayout1.setOnDoubleClickListener {
                    DisplayUtils.toVaccinesDetails(activity)
                }
                itemView.ItemLinearlayout2.setOnDoubleClickListener {
                    DisplayUtils.toVaccinesDetails(activity)
                }
            }
        }
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }
}